<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>鼠标事件对象</title>
    <style>
      #areaDiv {
        width: 400px;
        height: 300px;
        border: 1px solid #333;
      }

      #showMsg {
        margin-top: 40px;
        width: 200px;
        height: 24px;
        border: 1px solid #333;
      }
    </style>
  </head>
  <body>
    <div id="areaDiv"></div>
    <div id="showMsg"></div>

    <script>
      var areaDiv = document.getElementById("areaDiv");
      var showMsg = document.getElementById("showMsg");

      areaDiv.onmousemove = function (event) {
        event = event || window.event; // 兼容IE

        var x = event.clientX;
        var y = event.clientY;

        showMsg.innerHTML = `x=${x}, y=${y}`;
      };
    </script>
  </body>
</html>
